import { Component, OnInit, Input, Output } from '@angular/core';
import { Router } from '@angular/router';
import { BullySubjectService, Bully } from 'app/shared/service';
import { SYSTEM_EVENT } from 'app/app.constants';

@Component({
    selector: 'itmp-sys-msg-box',
    templateUrl: './sys-msg-box.component.html',
    styleUrls: ['./sys-msg-box.component.css']
})
export class SysMsgBoxComponent implements OnInit {
    @Input() messages = [];

    constructor(private router: Router, private bully: BullySubjectService) {}

    jumpTo(data: any) {
        data.isNew = false;
        const bully: Bully = {
            type: '',
            data
        };

        if (data.alarmId === undefined) {
            // alert
            bully.type = SYSTEM_EVENT.ALERT_EVENT;
            this.router.navigate(['/ccm/traffic-management/traffic-alert-page']);
        }

        if (data.alertID === undefined) {
            // alarm
            bully.type = SYSTEM_EVENT.ALARM_EVENT;
            this.router.navigate(['/ccm/equipment-management/equipment-alarm']);
        }

        // 延迟发送BS, 避免resetBS带来的副作用
        setTimeout(() => {
            this.bully.setBSubject(bully);
        }, 1000);
    }

    ngOnInit() {}
}
